<?php

/**
 * This is the model class for table "{{famliyinfo}}".
 *
 * The followings are the available columns in table '{{famliyinfo}}':
 * @property integer $id
 * @property string $userid
 * @property string $fname
 * @property string $fsex
 * @property string $fage
 * @property string $ftype
 * @property string $fmoney
 * @property string $fdbzh
 * @property string $fszsq
 * @property string $fUID
 * @property string $ftel
 * @property string $faddress
 * @property integer $tmpi1
 * @property integer $tmpi2
 * @property integer $tmpi3
 * @property string $tmps1
 * @property string $tmps2
 * @property string $tmps3
 */
class Famliyinfo extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{famliyinfo}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('userid, fname', 'required'),
			array('tmpi1, tmpi2, tmpi3', 'numerical', 'integerOnly'=>true),
			array('userid, fname, fsex, fage, ftype, fmoney, fdbzh, fszsq, fUID, ftel', 'length', 'max'=>20),
			array('faddress', 'length', 'max'=>100),
			array('tmps1, tmps2, tmps3', 'length', 'max'=>50),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, userid, fname, fsex, fage, ftype, fmoney, fdbzh, fszsq, fUID, ftel, faddress, tmpi1, tmpi2, tmpi3, tmps1, tmps2, tmps3', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
	   return array(
            //'hzxx'=>array(self::HAS_ONE,'Hzxx','','join'=>'inner join {{famliyinfo}} tf', 'on'=>'hzxx.userID=tf.userid','where'=>'userid='.$this->userid),
            'hzxx'=>array(self::BELONGS_TO,'Hzxx','userid'),
            //'hzxx'=>array(self::BELONGS_TO,'Hzxx','', 'join'=>'inner join {{famliyinfo}} tf', 'on'=>'tf.userID=hzxx.userid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '序号',
			'userid' => '户主身份证',
			'fname' => '姓名',
			'fsex' => '性别',
			'fage' => '年龄',
			'ftype' => '类别',
			'fmoney' => '保障金额',
			'fdbzh' => '低保证号',
			'fszsq' => '所在社区',
			'fUID' => '身份证',
			'ftel' => '联系电话',
			'faddress' => '家庭住址',
			'tmpi1' => 'Tmpi1',
			'tmpi2' => 'Tmpi2',
			'tmpi3' => 'Tmpi3',
			'tmps1' => 'Tmps1',
			'tmps2' => 'Tmps2',
			'tmps3' => 'Tmps3',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('userid',$this->userid,true);
		$criteria->compare('fname',$this->fname,true);
		$criteria->compare('fsex',$this->fsex,true);
		$criteria->compare('fage',$this->fage,true);
		$criteria->compare('ftype',$this->ftype,true);
		$criteria->compare('fmoney',$this->fmoney,true);
		$criteria->compare('fdbzh',$this->fdbzh,true);
		$criteria->compare('fszsq',$this->fszsq,true);
		$criteria->compare('fUID',$this->fUID,true);
		$criteria->compare('ftel',$this->ftel,true);
		$criteria->compare('faddress',$this->faddress,true);
		$criteria->compare('tmpi1',$this->tmpi1);
		$criteria->compare('tmpi2',$this->tmpi2);
		$criteria->compare('tmpi3',$this->tmpi3);
		$criteria->compare('tmps1',$this->tmps1,true);
		$criteria->compare('tmps2',$this->tmps2,true);
		$criteria->compare('tmps3',$this->tmps3,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Famliyinfo the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
